package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2024-12-22
 * Time: 21:07
 */
class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}


class Plate<T> {
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}


public class Test {
    public static void main1(String[] args) {
        Plate<Apple> message = new Plate<>();

        message.setMessage(new Apple());

        Plate<Banana> message2 = new Plate<>();

        message2.setMessage(new Banana());

        fun(message);

        fun(message2);
    }

    public static void main(String[] args) {
        Plate<Fruit> message = new Plate<>();

        message.setMessage(new Fruit());

        Plate<Food> message2 = new Plate<>();

        message2.setMessage(new Food());

        fun2(message);
        fun2(message2);
    }

    public static void fun2(Plate<? super Fruit> temp){
        temp.setMessage(new Banana());
        temp.setMessage(new Apple());

        //Fruit fruit = temp.getMessage();


    }

    //通配符的上界
    public static void fun(Plate<? extends Fruit> temp){
        //temp.setMessage(new Banana());
        //temp.setMessage(new Apple());  Fruit的子类有很多 所以 你不能添加
        System.out.println(temp.getMessage());
    }


   /* public static void main1(String[] args) {
        Message<String> message = new Message<>() ;
        message.setMessage("1111111111");
        fun(message);

        Message<Integer> message2 = new Message<>() ;
        message2.setMessage(123);
        fun(message2);

    }*/
}
